<template>
  <div id="DataMaintenance-procurement">
    <div class="flex-all pt10 pb10 pl12 pr12 bg-white height50">
      <div class="ct-head-left flex-al">
        <span class="left-line-orange mr10"></span>
        <span class="color-333 fs14">{{$t('repertorySet.repertorySettings.procurement.50zh7wclii00')}}</span>
      </div>
      <div class="cr-head-right">
        <el-button type="primary" size="mini" @click="handAdd">{{$t('repertorySet.repertorySettings.procurement.50zh9jww2zo0')}}</el-button>
      </div>
    </div>
    <div class="pAll12 bt_EBEEF5">
      <div class="flex-al Inquire-box mb12">
        <div class="ipt-box" style="width:250px;">
          <el-input
            v-model="filter.keyword"
            clearable
            :placeholder="$t('repertorySet.repertorySettings.procurement.50zh7wclmfw0')"
            @clear="search"
            @keyup.enter.native="search"
          ></el-input>
        </div>
        <el-button type="primary" size="mini" class="search-btn fs14" @click="search">{{$t('repertorySet.repertorySettings.procurement.50zh7wclmuo0')}}</el-button>
      </div>
      <div class="tableDiv" ref="auto_height_table">
        <settingTableCont :tableData="tableList">
          <!-- 按钮操作组********start -->
          <el-table-column ref="fixedColumn" :label="$t('repertorySet.repertorySettings.procurement.50zh7wcln5k0')" align="center" width="120px" fixed="right">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click.native.prevent="handSee(scope.row)">{{$t('repertorySet.repertorySettings.procurement.50zh7wclnhg0')}}</el-button>
              <el-button type="text" size="small" @click.native.prevent="handDelete(scope.row)">{{$t('repertorySet.repertorySettings.procurement.50zh7wclnt40')}}</el-button>
            </template>
          </el-table-column>
          <!-- 按钮操作组********end -->
        </settingTableCont>
        <!-- 分页 -->
        <el-pagination
          style="margin: 10px;"
          :current-page.sync="paging.curPage"
          :page-sizes="[10, 20, 30, 40]"
          :page-size.sync="paging.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="paging.pageTotal"
          @current-change="curPageChange"
          @size-change="pageSizeChange"
        ></el-pagination>
      </div>
    </div>
    <!-- 侧边弹窗******查看活动-->
    <el-drawer
      :title="$t('repertorySet.repertorySettings.procurement.50zh7wclo3k0')"
      :visible.sync="seeingVisable"
      direction="rtl"
      size="700px"
      :modal="false"
      custom-class="pop-slider--box validList-Box"
      :before-close="handleClose"
    >
      <div class="slider-btn">
        <el-button type="primary" size="mini" @click="handEdit()">{{$t('repertorySet.repertorySettings.procurement.50zh7wcloes0')}}</el-button>
      </div>
      <div class="slider-content">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane :label="$t('repertorySet.repertorySettings.procurement.50zh7wclopk0')" name="first">
            <div class="fs14 mt10">
              <div class="flex-al mb20">
                <span class="color-aaa mr20 dsplay" style="width: 70px;">{{$t('repertorySet.repertorySettings.procurement.50zh7wclozs0')}}</span>
                <span class="color-333">{{activityInfo.activitybuy_name}}</span>
              </div>
              <div class="flex-al mb20">
                <span class="color-aaa mr20 dsplay" style="width: 70px;">{{$t('repertorySet.repertorySettings.procurement.50zh7wclpcs0')}}</span>
                <span class="color-333">
                  {{activityInfo.activitybuy_stdate}}
                  {{$t('repertorySet.repertorySettings.procurement.50zh7wclpn00')}}
                  {{activityInfo.activitybuy_enddate}}
                </span>
              </div>
              <div class="flex-al mb20">
                <span class="color-aaa mr20 dsplay" style="width: 70px;">{{$t('repertorySet.repertorySettings.procurement.50zh7wclpxs0')}}</span>
                <span class="color-333" v-if="activityInfo.activitybuy_apply==0">{{$t('repertorySet.repertorySettings.procurement.50zh7wclqac0')}}</span>
                <span class="color-333" v-else-if="activityInfo.activitybuy_apply==1">{{$t('repertorySet.repertorySettings.procurement.50zh7wclqk80')}}</span>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane :label="$t('repertorySet.repertorySettings.procurement.50zh7wclqv00')" name="second">
            <div class="flex-all mb10">
              <div class="flex-al Inquire-box">
                <div class="ipt-box" style="width:250px;">
                  <el-input
                    v-model="tableListFoods.keyword"
                    clearable
                    :placeholder="$t('repertorySet.repertorySettings.procurement.50zh7wclr5g0')"
                    @clear="search1"
                    @keyup.enter.native="search1"
                  ></el-input>
                </div>
                <el-button type="primary" size="mini" class="search-btn fs14" @click="search1">{{$t('repertorySet.repertorySettings.procurement.50zh7wclmuo0')}}</el-button>
              </div>
            </div>
            <div class="foods-table" ref="auto_height_foods_table">
              <noBorderTableCont :tableData="tableListFoods"></noBorderTableCont>
            </div>
          </el-tab-pane>
          <el-tab-pane v-if="activityInfo.activitybuy_apply == 0" :label="$t('repertorySet.repertorySettings.procurement.50zh7wclrj40')" name="third">
            <div class="flex-all mb10">
              <span>{{$t('repertorySet.repertorySettings.procurement.add1')}}{{tableListGraden.list.length}}</span>
            </div>
            <div class="graden-table" ref="auto_height_graden_table">
              <noBorderTableCont :tableData="tableListGraden"></noBorderTableCont>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-drawer>
    <!-- 侧边弹窗******新增或者编辑采购活动 -->
    <el-drawer
      :title="propData.isEdit?'编辑活动':'发布活动'"
      :visible.sync="propData.cancelVisible"
      direction="rtl"
      size="700px"
      :modal="false"
      custom-class="pop-slider--box"
      :before-close="propData.handleClose"
    >
      <div class="slider-btn" v-if="activeName=='first'">
        <el-button v-if="!propData.isEdit" type="primary" size="mini" @click="onSubmit">{{$t('repertorySet.repertorySettings.procurement.50zh7wclrwc0')}}</el-button>
        <el-button v-else type="primary" size="mini" @click="onEditSubmit">{{$t('repertorySet.repertorySettings.procurement.50zh7wclrwc0')}}</el-button>
      </div>
      <div class="slider-content">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane :label="$t('repertorySet.repertorySettings.procurement.50zh7wclopk0')" name="first" :disabled="fidisable">
            <el-form label-width="85px" :model="ruleForm" :rules="rules" ref="ruleForm">
              <el-form-item :label="$t('repertorySet.repertorySettings.procurement.50zh7wclozs0')" prop="activitybuy_name">
                <el-input
                  clearable
                  :placeholder="$t('repertorySet.repertorySettings.procurement.50zh7wclsbo0')"
                  v-model="ruleForm.activitybuy_name"
                  style="width:320px;"
                ></el-input>
              </el-form-item>
              <el-form-item :label="$t('repertorySet.repertorySettings.procurement.50zh7wclpcs0')" prop="times">
                <div class="flex-al">
                  <div class="select-box" style="width:320px;">
                    <el-date-picker
                      v-model="ruleForm.times"
                      type="daterange"
                      :range-separator="$t('repertorySet.repertorySettings.procurement.50zh7wclpn00')"
                      value-format="yyyy-MM-dd"
                      :start-placeholder="$t('repertorySet.repertorySettings.procurement.50zh7wclsmc0')"
                      :end-placeholder="$t('repertorySet.repertorySettings.procurement.50zh7wclsyk0')"
                    ></el-date-picker>
                  </div>
                </div>
              </el-form-item>
              <el-form-item :label="$t('repertorySet.repertorySettings.procurement.50zh7wclrj40')" prop="activitybuy_apply">
                <el-radio-group v-model="ruleForm.activitybuy_apply">
                  <el-radio label="1">{{$t('repertorySet.repertorySettings.procurement.50zh7wclt700')}}</el-radio>
                  <el-radio label="0">{{$t('repertorySet.repertorySettings.procurement.50zh7wcltg00')}}</el-radio>
                </el-radio-group>
              </el-form-item>
              <!-- <p class="color-red">* 为必填字段</p> -->
            </el-form>
          </el-tab-pane>
          <el-tab-pane :label="$t('repertorySet.repertorySettings.procurement.50zh7wclqv00')" name="second" :disabled="sedisable">
            <div class="flex-all mb10">
              <div class="flex-al Inquire-box">
                <div class="ipt-box" style="width:250px;">
                  <el-input
                    v-model="tableListFoods.keyword"
                    clearable
                    :placeholder="$t('repertorySet.repertorySettings.procurement.50zh7wclr5g0')"
                    @clear="search1"
                    @keyup.enter.native="search1"
                  ></el-input>
                </div>
                <el-button type="primary" size="mini" class="search-btn fs14" @click="search1">{{$t('repertorySet.repertorySettings.procurement.50zh7wclmuo0')}}</el-button>
              </div>
              <el-button type="primary" size="mini" @click="addFoods">{{$t('repertorySet.repertorySettings.procurement.50zh7wclto80')}}</el-button>
            </div>
            <div class="foods-table" ref="auto_height_foods_table">
              <noBorderTableCont :tableData="tableListFoods">
                <!-- 按钮操作组********start -->
                <el-table-column
                  ref="fixedColumn"
                  :label="$t('repertorySet.repertorySettings.procurement.50zh7wcln5k0')"
                  align="center"
                  width="120px"
                  fixed="right"
                >
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      size="small"
                      @click.native.prevent="delFoods(scope.row)"
                    >{{$t('repertorySet.repertorySettings.procurement.50zh7wcltx00')}}</el-button>
                  </template>
                </el-table-column>
                <!-- 按钮操作组********end -->
              </noBorderTableCont>
            </div>
          </el-tab-pane>
          <el-tab-pane v-if="ruleForm.activitybuy_apply == 0" :label="$t('repertorySet.repertorySettings.procurement.50zh7wclrj40')" name="third" :disabled="sedisable">
            <div class="flex-all mb10">
              <span>{{$t('repertorySet.repertorySettings.procurement.add1')}}{{tableListGraden.list.length}}</span>
              <el-button type="primary" size="mini" @click="addGraden">{{$t('repertorySet.repertorySettings.procurement.50zh7wclu5k0')}}</el-button>
            </div>
            <div class="graden-table" ref="auto_height_graden_table">
              <noBorderTableCont :tableData="tableListGraden">
                <!-- 按钮操作组********start -->
                <el-table-column
                  ref="fixedColumn"
                  :label="$t('repertorySet.repertorySettings.procurement.50zh7wcln5k0')"
                  align="center"
                  width="120px"
                  fixed="right"
                >
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      size="small"
                      @click.native.prevent="delGraden(scope.row)"
                    >{{$t('repertorySet.repertorySettings.procurement.50zh7wcltx00')}}</el-button>
                  </template>
                </el-table-column>
                <!-- 按钮操作组********end -->
              </noBorderTableCont>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-drawer>
    <!-- 添加货品****弹框 -->
    <addFoods
      :addFoods="addActiveFoods"
      @handFoodsConfirm="handFoodsConfirm"
      @handleCloseFrame="addActiveFoods=false"
    ></addFoods>
    <!-- 添加园所****弹框 -->
    <addActive
      :addSuitGraden="addSuitGraden"
      @handConfirm="handConfirm"
      @handleCloseFrame="addSuitGraden=false"
    ></addActive>
    <!--删除适用园所弹窗 -->
    <popTips
      :dialogVisable="delSuitGraden"
      :popTipsCont="popTips_delSuitGraden"
      @handConfirm="delActivityBuySchoolAction"
      @handCancel="delSuitGraden=false"
      @handleCloseTip="delSuitGraden=false"
    ></popTips>
    <!--删除活动货品弹窗 -->
    <popTips
      :dialogVisable="delActiveFoods"
      :popTipsCont="popTips_delActiveFoods"
      @handConfirm="delActivityBuyGoodsAction"
      @handCancel="delActiveFoods=false"
      @handleCloseTip="delActiveFoods=false"
    ></popTips>
    <!-- 删除采购活动 -->
    <popTips
      :dialogVisable="delItem"
      :popTipsCont="popTips_del"
      @handConfirm="delAction"
      @handCancel="delItem=false"
      @handleCloseTip="delItem=false"
    ></popTips>
  </div>
</template>

<script>
import settingTableCont from "@/components/tables/settingTableCont.vue";
import popTips from "@/components/common/popTips/popTips.vue";
import addActive from "@/components/Graden/addActive.vue";
import addFoods from "@/components/ActiveFoods/addFoods.vue";
import setHttp from "../../Set";

import noBorderTableCont from "@/components/tables/noBorderTableCont.vue";
export default {
  name: "setting",
  components: {
    settingTableCont,
    popTips,
    addActive,
    addFoods,
    noBorderTableCont
  },
  data() {
    return {
      activitybuyId: "",
      goodsId: "",
      schoolId: "",
      activityInfo: "",
      fidisable: false, //tab切换是否显示
      sedisable: false, //tab切换是否显示

      seeingVisable: false, //查看采购活动
      delItem: false, //删除采购活动
      addSuitGraden: false, //添加适用园所
      addActiveFoods: false, //添加活动货品
      //删除采购活动****弹窗
      popTips_del: {
        btn_text1: this.$t('repertorySet.repertorySettings.procurement.50zh7wclrwc0'),
        btn_text2: this.$t('repertorySet.repertorySettings.procurement.50zh7wcludw0'),
        title: this.$t('repertorySet.repertorySettings.procurement.50zh7wclumg0'),
        context: this.$t('repertorySet.repertorySettings.procurement.50zh7wclux80')
      },
      delActiveFoods: false, //-删除活动货品
      popTips_delActiveFoods: {
        btn_text1: this.$t('repertorySet.repertorySettings.procurement.50zh7wclrwc0'),
        btn_text2: this.$t('repertorySet.repertorySettings.procurement.50zh7wcludw0'),
        title: "-删除活动货品",
        context: this.$t('repertorySet.repertorySettings.procurement.50zh7wclux80')
      },
      delSuitGraden: false, //删除适用园所
      popTips_delSuitGraden: {
        btn_text1: this.$t('repertorySet.repertorySettings.procurement.50zh7wclrwc0'),
        btn_text2: this.$t('repertorySet.repertorySettings.procurement.50zh7wcludw0'),
        title: this.$t('repertorySet.repertorySettings.procurement.50zh7wclv880'),
        context: this.$t('repertorySet.repertorySettings.procurement.50zh7wclux80')
      },
      activeName: "first",
      //检索-table
      filter: {
        keyword: ""
      },
      // 表格数据
      tableList: {
        // 表格的列
        columns: [],
        // 表格数据
        list: [],
        options: {
          errortip: "", //空页面提示内容
          mutiSelect: false, //是否显示多选
          issetting: false, //是否可以编辑列
          tableHeight: 0
        }
      },
      // 分页
      paging: {
        curPage: 1,
        pageSize: 10,
        pageTotal: 0
      },
      // 活动货品表格数据
      tableListFoods: {
        // 表格的列
        columns: [],
        // 表格数据
        list: [],
        options: {
          errortip: "", //空页面提示内容
          mutiSelect: false, //是否显示多选
          issetting: false, //是否可以编辑列
          tableHeight: "0px" //表格高度
        },
        keyword: "", //关键词
        // 分页
        curPage: 1,
        pageSize: 10,
        pageTotal: 0
      },
      // 适用园所表格数据
      tableListGraden: {
        // 表格的列
        columns: [],
        // 表格数据
        list: [],
        options: {
          errortip: "", //空页面提示内容
          mutiSelect: false, //是否显示多选
          issetting: false, //是否可以编辑列
          tableHeight: "0px" //表格高度
        },
        // 分页
        curPage: 1,
        pageSize: 10,
        pageTotal: 0
      },
      //侧边弹窗******新增或者编辑采购活动
      propData: {
        cancelVisible: false, //新增或者编辑采购活动
        isEdit: false //是否编辑采购活动
      },
      // 表单
      ruleForm: {
        activitybuy_name: "",
        times: "",
        activitybuy_apply: ""
      },
      // 表单验证
      rules: {
        activitybuy_name: [
          {
            required: true,
            message: this.$t('repertorySet.repertorySettings.procurement.50zh7wclvhk0'),
            trigger: "blur"
          }
        ],
        times: [
          {
            required: true,
            message: this.$t('repertorySet.repertorySettings.procurement.50zh7wclvuk0'),
            trigger: "change"
          }
        ],
        activitybuy_apply: [
          {
            required: true,
            message: this.$t('repertorySet.repertorySettings.procurement.50zh7wclw4s0'),
            trigger: "change"
          }
        ]
      }
    };
  },
  created() {
    this.getActivityBuyList();
  },
  methods: {
    //集团订购管理->获取采购活动列表
    getActivityBuyList() {
      setHttp
        .getActivityBuyList({
          is_count: "1", //是否需要总数，可以不传
          p: this.paging.curPage,
          num: this.paging.pageSize,
          //筛选条件
          keyword: this.filter.keyword
        })
        .then(res => {
          this.paging.pageTotal = parseInt(res.data.result.all_num);
          this.tableList.columns = res.data.result.field;
          console.log(res);
          if (res.data.error == 0) {
            this.tableList.list = res.data.result.list;
          } else {
            this.tableList.list = [];
            this.tableList.options.errortip = res.data.errortip;
          }
        });
    },
    //检索
    search() {
      this.paging.curPage = 1;
      this.getActivityBuyList();
    },
    //检索
    search1() {
      this.getActivityBuyGoodsList();
    },
    //新增
    handAdd() {
      this.activeName = "first";
      this.fidisable = false;
      this.sedisable = true;
      this.propData.isEdit = false; //是否编辑采购活动
      this.propData.cancelVisible = !this.propData.cancelVisible;
      this.resetForm("ruleForm");
    },
    //查看
    handSee(row) {
      this.activeName = "first";
      this.fidisable = false;
      this.sedisable = false;
      this.activityInfo = row;
      this.activitybuyId = row.activitybuy_id;
      this.seeingVisable = !this.seeingVisable;
    },
    //编辑
    handEdit() {
      this.resetForm("ruleForm");
      this.activeName = "first";
      this.ruleForm = {
        activitybuy_name: this.activityInfo.activitybuy_name,
        activitybuy_apply: this.activityInfo.activitybuy_apply,
        times: [
          this.activityInfo.activitybuy_stdate,
          this.activityInfo.activitybuy_enddate
        ]
      };
      this.propData.isEdit = true; //是否编辑采购活动
      this.seeingVisable = false;
      this.propData.cancelVisible = !this.propData.cancelVisible;
    },
    //删除
    handDelete(row) {
      this.activitybuyId = row.activitybuy_id;
      this.delItem = !this.delItem;
    },
    //删除活动
    delAction() {
      setHttp
        .delActivityBuyAction({
          activitybuy_id: this.activitybuyId
        })
        .then(res => {
          console.log(res);
          if (res.data.error == 0) {
            this.$message({ message: res.data.errortip, type: "success" });
            this.delItem = false;
            this.getActivityBuyList();
          } else {
            this.$message.error(res.data.errortip);
          }
        });
    },

    // 添加活动货品
    addFoods() {
      this.addActiveFoods = !this.addActiveFoods;
    },
    // 删除活动货品
    delFoods(v) {
      this.delActiveFoods = !this.delActiveFoods;
      this.goodsId = v.goods_id;
    },
    // 删除活动货品 确认
    delActivityBuyGoodsAction() {
      setHttp
        .delActivityBuyGoodsAction({
          activitybuy_id: this.activitybuyId,
          goods_id: this.goodsId
        })
        .then(res => {
          if (res.data.error == 0) {
            this.$message({ message: res.data.errortip, type: "success" });
            this.delActiveFoods = false;
            this.getActivityBuyGoodsList();
          } else {
            this.$message.error(res.data.errortip);
          }
        });
    },
    // 添加活动货品确定提交
    handFoodsConfirm(val) {
      console.log(val);
      this.suitFoods = [];
      val.forEach(v => {
        this.suitFoods.push({
          goods_id: v.goods_id,
          activitybuy_id: this.activitybuyId
        });
      });
      setHttp
        .addActivityBuyGoodsAction({
          goods: JSON.stringify(this.suitFoods)
        })
        .then(res => {
          if (res.data.error == "0") {
            this.$message({
              message: res.data.errortip,
              type: "success"
            });
            this.getActivityBuyGoodsList();
            this.addActiveFoods = false;
          } else {
            this.$message.error(res.data.errortip);
          }
        });
    },
    // 添加园所
    addGraden() {
      this.addSuitGraden = !this.addSuitGraden;
    },
    // 删除园所
    delGraden(v) {
      this.delSuitGraden = !this.delSuitGraden;
      this.schoolId = v.school_id;
    },
    // 删除园所 确认
    delActivityBuySchoolAction() {
      setHttp
        .delActivityBuySchoolAction({
          activitybuy_id: this.activitybuyId,
          school_id: this.schoolId
        })
        .then(res => {
          if (res.data.error == 0) {
            this.$message({ message: res.data.errortip, type: "success" });
            this.delSuitGraden = false;
            this.getActivityBuySchoolList();
          } else {
            this.$message.error(res.data.errortip);
          }
        });
    },
    // 添加园所确定提交
    handConfirm(val) {
      console.log(val);
      this.suitGraden = [];
      val.forEach(v => {
        this.suitGraden.push({
          school_id: v.school_id,
          activitybuy_id: this.activitybuyId
        });
      });
      setHttp
        .addActivityBuySchoolAction({
          school: JSON.stringify(this.suitGraden)
        })
        .then(res => {
          if (res.data.error == "0") {
            this.$message({
              message: res.data.errortip,
              type: "success"
            });
            this.getActivityBuySchoolList();
            this.addSuitGraden = false;
          } else {
            this.$message.error(res.data.errortip);
          }
        });
    },
    // 活动货品列表
    getActivityBuyGoodsList() {
      setHttp
        .getActivityBuyGoodsList({
          keyword: this.tableListFoods.keyword,
          activitybuy_id: this.activitybuyId
        })
        .then(res => {
          this.tableListFoods.columns = res.data.result.field;
          console.log(res);
          if (res.data.error == 0) {
            this.tableListFoods.list = res.data.result.list;
          } else {
            this.tableListFoods.list = [];
            this.tableListFoods.options.errortip = res.data.errortip;
          }
        });
    },
    // 适用园所列表
    getActivityBuySchoolList() {
      setHttp
        .getActivityBuySchoolList({
          activitybuy_id: this.activitybuyId
        })
        .then(res => {
          this.tableListGraden.columns = res.data.result.field;
          console.log(res);
          if (res.data.error == 0) {
            this.tableListGraden.list = res.data.result.list;
          } else {
            this.tableListGraden.list = [];
            this.tableListGraden.options.errortip = res.data.errortip;
          }
        });
    },
    // 切换选项卡
    handleClick(tab, event) {
      console.log(tab, event);
      if (this.activeName == "second") {
        this.getActivityBuyGoodsList();
        this.$nextTick(() => {
          if (this.$refs["auto_height_foods_table"]) {
            this.tableListFoods.options.tableHeight = this.$Tool.getTableHeight(
              this.$refs.auto_height_foods_table.getBoundingClientRect().top +
                75
            );
          }
        });
      } else if (this.activeName == "third") {
        this.getActivityBuySchoolList();
        this.$nextTick(() => {
          if (this.$refs["auto_height_graden_table"]) {
            this.tableListGraden.options.tableHeight = this.$Tool.getTableHeight(
              this.$refs.auto_height_graden_table.getBoundingClientRect().top +
                75
            );
          }
        });
      }
    },
    //侧边弹窗 - 新增 - 提交
    onSubmit() {
      let canSubmit = this.$Tool.isNull("ruleForm", this);
      if (canSubmit) {
        setHttp
          .addActivityBuyAction({
            activitybuy_name: this.ruleForm.activitybuy_name,
            activitybuy_apply: this.ruleForm.activitybuy_apply,
            activitybuy_stdate: this.ruleForm.times
              ? this.ruleForm.times[0]
              : "",
            activitybuy_enddate: this.ruleForm.times
              ? this.ruleForm.times[1]
              : ""
          })
          .then(res => {
            if (res.data.error == 0) {
              this.$message({ message: res.data.errortip, type: "success" });
              this.activitybuyId = res.data.id;
              console.log(this.activitybuyId);
              this.activeName = "second";
              this.fidisable = true;
              this.sedisable = false;
              this.getActivityBuyList();
              this.handleClick();
            } else {
              this.$message.error(res.data.errortip);
            }
          });
      }
    },
    //侧边弹窗 - 编辑 - 提交
    onEditSubmit() {
      let canSubmit = this.$Tool.isNull("ruleForm", this);
      if (canSubmit) {
        setHttp
          .updateActivityBuyAction({
            activitybuy_id: this.activitybuyId,
            activitybuy_name: this.ruleForm.activitybuy_name,
            activitybuy_apply: this.ruleForm.activitybuy_apply,
            activitybuy_stdate: this.ruleForm.times
              ? this.ruleForm.times[0]
              : "",
            activitybuy_enddate: this.ruleForm.times
              ? this.ruleForm.times[1]
              : ""
          })
          .then(res => {
            console.log(res);
            if (res.data.error == 0) {
              this.$message({ message: res.data.errortip, type: "success" });
              this.activeName = "second";
              this.getActivityBuyList();
              this.handleClick();
            } else {
              this.$message.error(res.data.errortip);
            }
          });
      }
    },
    // 页码变化
    curPageChange(v) {
      this.paging.curPage = v;
      this.getActivityBuyList();
    },
    // pageSize改变
    pageSizeChange() {
      this.paging.curPage = 1;
      this.getActivityBuyList();
    },
    // 重置表单
    resetForm(form) {
      // 数据清空
      this.ruleForm = {
        activitybuy_name: "",
        times: "",
        activitybuy_apply: ""
      };
      if (this.$refs[form]) {
        this.$refs[form].resetFields();
      }
    },
    //侧边弹窗-关闭
    handleClose(done) {
      done();
    }
  },
  mounted() {
    this.$nextTick(() => {
      if (this.$refs["auto_height_table"]) {
        this.tableList.options.tableHeight = this.$Tool.getTableHeight(
          this.$refs.auto_height_table.getBoundingClientRect().top + 55
        );
      }
    });
  }
};
</script>

<style lang="less">
// #DataMaintenance-procurement {
// }
</style>
